package com.wn.web;

import com.github.pagehelper.PageInfo;
import com.wn.common.pojo.PageParam;
import com.wn.common.pojo.Rsp;
import com.wn.common.pojo.ScenicSpots;
import com.wn.service.ScenicSpotsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;



@RestControllerAdvice
@RequestMapping("scenicspots")
@Api(value = "景点接口",description = "景点接口")
public class ScenicSpotsController {
    @Autowired
    private ScenicSpotsService scenicSpotsService;

    /**
     * 查询所有景点并分页
     * @param
     * @param
     * @return
     */
    @PostMapping("queryAll")
    public Rsp queryAll(@RequestBody PageParam<ScenicSpots> scenicSpotsPageParam){
        PageInfo<ScenicSpots> scenicSpotsPageInfo = scenicSpotsService.queryAll(scenicSpotsPageParam);
        return new Rsp().success(scenicSpotsPageInfo);
    }

    /**
     * 根据id查询景点
     * @return
     */
    @PostMapping("getScenicSpotsById")
    public Rsp getScenicSpotsById(@RequestBody ScenicSpots scenicSpots){
        Rsp scenicSpotsById = scenicSpotsService.getScenicSpotsById(scenicSpots.getId());
        return scenicSpotsById;
    }

    /**
     * 添加景点
     * @param scenicSpots
     * @return
     */
    @PostMapping("addScenicSpots")
    public Rsp insertAll(@RequestBody @Valid ScenicSpots scenicSpots){
        Rsp rsp = scenicSpotsService.insertAll(scenicSpots);
        return rsp;
    }

    /**
     * 更新景点数据
     * @param scenicSpots
     * @return
     */
    @PostMapping("updateScenicSpots")
    public  Rsp UpdateScenicSpots( @RequestBody @Valid ScenicSpots scenicSpots){
        System.out.println(scenicSpots.toString());
        Rsp updateScenicSpots = scenicSpotsService.UpdateScenicSpots(scenicSpots);
        return updateScenicSpots;
    }

    /**
     * 根据id删除
     * @param
     * @return
     */
    @PostMapping("deleteByPrimaryKey")
    public Rsp deleteByPrimaryKey(@RequestBody ScenicSpots scenicSpots){
        Rsp deleteByPrimaryKey = scenicSpotsService.deleteByPrimaryKey(scenicSpots);
        return deleteByPrimaryKey;
    }

    /**
     * 修改状态
     * @param scenicSpots
     * @return
     */
    @PostMapping("updateNewsinfo")
    public Rsp updateNewsinfo(@RequestBody ScenicSpots scenicSpots){
        Rsp rsp = scenicSpotsService.updateNewsinfo(scenicSpots);
        return rsp;
    }

    /**
     * 根据首页点击景点名查询景点表中的景点
     * @return
     */
    @PostMapping("getscenicSpotsByName")
    public Rsp getscenicSpotsByName(@RequestBody ScenicSpots scenicSpots){
        Rsp rsp = scenicSpotsService.getscenicSpotsByName(scenicSpots);

        return rsp;

    }
}
